package com.br.sae.model.dao;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Query;

import com.br.sae.conexaobd.SistemaDAO;
import com.br.sae.model.entitys.Professor;
import com.br.sae.model.entitys.Turma;
import com.br.sae.model.entitys.Usuario;

public class TurmaBD {

	public List<Turma> consultaTurma() {
		Query query = SistemaDAO.createNamedQuery("TurmaBy");
		return query.getResultList();
	}

	public List<Turma> consultaTurma(String nivel) {

		String sql = "SELECT turma FROM Turma turma WHERE turma.nivel= :nivel";

		Query query = SistemaDAO.createQuery(sql);
		query.setParameter("nivel", nivel);

		return query.getResultList();
	}

	public List<Turma> consultaTurma(String nome, String nivel) {
		String sql = "SELECT turma FROM Turma turma WHERE turma.nome= :nome AND turma.nivel= :nivel";

		Query query = SistemaDAO.createQuery(sql);
		query.setParameter("nome", nome);
		query.setParameter("nivel", "Superior");

		return query.getResultList();
	}

	public List<Turma> consultaTurmaSerie(String nivel, String serie) {
		String sql = "SELECT turma FROM Turma turma WHERE turma.nivel= :nivel AND turma.serie= :serie";
		Query query = SistemaDAO.createQuery(sql);
		query.setParameter("nivel", nivel);
		query.setParameter("serie", serie);
		return query.getResultList();
	}

	public boolean incluirTurma(Turma turma) {
		try {
			SistemaDAO.persistTurma(turma);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	public boolean alterarTurma(Turma turma) {
		try {
			SistemaDAO.updateTurma(turma);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	public boolean removerTurma(Turma turma) {
		try {
			SistemaDAO.removerTurma(turma);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

}
